<xsl:stylesheet
    version="1.0"
    exclude-result-prefixes="x xsl cmswrt cbq"
    xmlns:x="http://www.w3.org/2001/XMLSchema"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime"
    xmlns:cbq="urn:schemas-microsoft-com:ContentByQueryWebPart">
  <xsl:output method="html" indent="no" />
  <xsl:param name="cbq_isgrouping" />
  <xsl:param name="cbq_columnwidth" />
  <xsl:param name="Group" />
  <xsl:param name="GroupType" />
  <xsl:param name="cbq_iseditmode" />
  <xsl:param name="cbq_viewemptytext" />
  <xsl:param name="SiteId" />
  <xsl:param name="WebUrl" />
  <xsl:param name="PageId" />
  <xsl:param name="WebPartId" />
  <xsl:param name="FeedPageUrl" />
  <xsl:param name="FeedEnabled" />
  <xsl:param name="SiteUrl" />
  <xsl:param name="BlankTitle" />
  <xsl:param name="BlankGroup" />
  <xsl:param name="UseCopyUtil" />
  <xsl:param name="DataColumnTypes" />
  <xsl:param name="ClientId" />
  <xsl:template match="/">
    <xsl:call-template name="OuterTemplate" />
  </xsl:template>

  <xsl:template name="OuterTemplate">
    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
    <xsl:variable name="RowCount" select="count($Rows)" />

      <xsl:choose>
        <xsl:when test="$RowCount=0">
          <xsl:call-template name="OuterTemplate.Empty">
            <xsl:with-param name="EditMode" select="$cbq_iseditmode" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="OuterTemplate.Body">
            <xsl:with-param name="Rows" select="$Rows" />
            <xsl:with-param name="RowCount" select="$RowCount" />
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
      
  </xsl:template>

  <xsl:template name="OuterTemplate.Empty">
    <xsl:param name="EditMode" />

        <xsl:if test="$EditMode = 'True'">
          <div class="wp-content description">
            <xsl:value-of disable-output-escaping="yes" select="$cbq_viewemptytext" />
          </div>
        </xsl:if>

  </xsl:template>

  <xsl:template name="OuterTemplate.Body">
    <xsl:param name="Rows" />
    <xsl:param name="RowCount" />

    <xsl:for-each select="$Rows">
      
        <div style="padding-bottom:12px;">
          <xsl:call-template name="OuterTemplate.CallItemTemplate" />
        </div>
      
    </xsl:for-each>
	
	<table width="320px">
		<tr>
			<td>
				<a id="PevPageLink1" href="javascript:PrevPage();" style="color:white;">&lt;Prev </a>
				<script type="text/javascript">CheckPrevPageLink("PevPageLink1");</script>
			</td>
			<td align="right">
				<a href="javascript:NextPage();" style="color:white;"> Next&gt;</a>
			</td>
		</tr>
	</table>

  </xsl:template>

  <xsl:template name="OuterTemplate.CallItemTemplate">
    <xsl:choose>
      <xsl:when test="@Style='PsmsMobileItem'">
        <xsl:apply-templates select="." mode="itemstyle">
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="." mode="itemstyle">
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetSafeLink">
    <xsl:param name="UrlColumnName"/>
    <xsl:if test="$UseCopyUtil = 'True'">
      <xsl:value-of select="concat('/_layouts/CopyUtil.aspx?Use=id&amp;Action=dispform&amp;ItemId=',@ID,'&amp;ListId=',@ListId,'&amp;WebId=',@WebId,'&amp;SiteId=',$SiteId)"/>
    </xsl:if>
    <xsl:if test="$UseCopyUtil != 'True'">
      <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
        <xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetSafeUserLink">
    <xsl:param name="SharePointUser" />
    <xsl:variable name="Id" select="substring-before($SharePointUser, ';')" />
    <xsl:variable name="Name">
      <xsl:call-template name="OuterTemplate.GetUserNameFromSharePointUser">
        <xsl:with-param name="SharePointUser" select="$SharePointUser" />
      </xsl:call-template>
    </xsl:variable>

    <a class="am-userlink" href="/Pages/PodcasterDetail.aspx?aid={$Id}">
      <xsl:value-of select="$Name" />
    </a>

  </xsl:template>

  <xsl:template name="OuterTemplate.GetUserNameFromSharePointUser">
    <xsl:param name="SharePointUser" />
    <xsl:choose>
      <xsl:when test="contains($SharePointUser, '\')">
        <xsl:value-of select="substring-after($SharePointUser, '\')" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring-after($SharePointUser, '#')" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetTitle">
    <xsl:param name="Title"/>
    <xsl:param name="UrlColumnName"/>
    <xsl:if test="string-length($Title) != 0">
      <xsl:value-of select="$Title"/>
    </xsl:if>
    <xsl:if test="string-length($Title) = 0">
      <xsl:if test="$UseCopyUtil = 'True'">
        <xsl:value-of select="$BlankTitle" />
      </xsl:if>
      <xsl:if test="$UseCopyUtil != 'True'">
        <xsl:call-template name="OuterTemplate.GetPageNameFromUrl">
          <xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.FormatColumnIntoUrl">
    <xsl:param name="UrlColumnName"/>
    <xsl:variable name="Value" select="@*[name()=$UrlColumnName]"/>
    <xsl:if test="contains($DataColumnTypes,concat(';',$UrlColumnName,',URL;'))">
      <xsl:call-template name="OuterTemplate.FormatValueIntoUrl">
        <xsl:with-param name="Value" select="$Value"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:if test="not(contains($DataColumnTypes,concat(';',$UrlColumnName,',URL;')))">
      <xsl:value-of select="$Value"/>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.FormatValueIntoUrl">
    <xsl:param name="Value"/>
    <xsl:if test="not(contains($Value,', '))">
      <xsl:value-of select="$Value"/>
    </xsl:if>
    <xsl:if test="contains($Value,', ')">
      <xsl:call-template name="OuterTemplate.Replace">
        <xsl:with-param name="Value" select="substring-before($Value,', ')"/>
        <xsl:with-param name="Search" select="',,'"/>
        <xsl:with-param name="Replace" select="','"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.Replace">
    <xsl:param name="Value"/>
    <xsl:param name="Search"/>
    <xsl:param name="Replace"/>
    <xsl:if test="contains($Value,$Search)">
      <xsl:value-of select="concat(substring-before($Value,$Search),$Replace)"/>
      <xsl:call-template name="OuterTemplate.Replace">
        <xsl:with-param name="Value" select="substring-after($Value,$Search)"/>
        <xsl:with-param name="Search" select="$Search"/>
        <xsl:with-param name="Replace" select="$Replace"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:if test="not(contains($Value,$Search))">
      <xsl:value-of select="$Value"/>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetSafeStaticUrl">
    <xsl:param name="UrlColumnName"/>
    <xsl:variable name="Url">
      <xsl:call-template name="OuterTemplate.FormatColumnIntoUrl">
        <xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="cmswrt:EnsureIsAllowedProtocol($Url)"/>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetColumnDataForUnescapedOutput">
    <xsl:param name="Name"/>
    <xsl:param name="MustBeOfType"/>
    <xsl:if test="contains($DataColumnTypes,concat(';',$Name,',',$MustBeOfType,';'))">
      <xsl:value-of select="@*[name()=$Name]"/>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetPageNameFromUrl">
    <xsl:param name="UrlColumnName"/>
    <xsl:variable name="Url">
      <xsl:call-template name="OuterTemplate.FormatColumnIntoUrl">
        <xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:call-template name="OuterTemplate.GetPageNameFromUrlRecursive">
      <xsl:with-param name="Url" select="$Url"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetPageNameFromUrlRecursive">
    <xsl:param name="Url"/>
    <xsl:choose>
      <xsl:when test="contains($Url,'/') and substring($Url,string-length($Url)) != '/'">
        <xsl:call-template name="OuterTemplate.GetPageNameFromUrlRecursive">
          <xsl:with-param name="Url" select="substring-after($Url,'/')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$Url"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="OuterTemplate.GetGroupName">
    <xsl:param name="GroupName"/>
    <xsl:param name="GroupType"/>
    <xsl:choose>
      <xsl:when test="string-length(normalize-space($GroupName)) = 0">
        <xsl:value-of select="$BlankGroup"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$GroupType='URL'">
            <xsl:variable name="Url">
              <xsl:call-template name="OuterTemplate.FormatValueIntoUrl">
                <xsl:with-param name="Value" select="$GroupName"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:call-template name="OuterTemplate.GetPageNameFromUrlRecursive">
              <xsl:with-param name="Url" select="$Url"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$GroupName" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="OuterTemplate.CallPresenceStatusIconTemplate">
    <xsl:if test="string-length(@SipAddress) != 0">
      <span class="presence-status-icon">
        <img src="/_layouts/images/imnhdr.gif" onload="IMNRC('{@SipAddress}')" ShowOfflinePawn="1" alt="" id="{concat('MWP_pawn_',$ClientId,'_',@ID,'type=sip')}"/>
      </span>
    </xsl:if>
  </xsl:template>

  <xsl:template name="OuterTemplate.FormatDate">
    <xsl:param name="DateTime" />
    <!-- get date info -->
    <xsl:variable name="year">
      <xsl:value-of select="substring($DateTime,1,4)" />
    </xsl:variable>
    <xsl:variable name="month-temp">
      <xsl:value-of select="substring-after($DateTime,'-')" />
    </xsl:variable>
    <xsl:variable name="month">
      <xsl:value-of select="substring-before($month-temp,'-')" />
    </xsl:variable>
    <xsl:variable name="day-temp">
      <xsl:value-of select="substring-after($month-temp,'-')" />
    </xsl:variable>
    <xsl:variable name="day">
      <xsl:value-of select="substring($month-temp,1,2)" />
    </xsl:variable>
    <!-- return -->
    <xsl:value-of select="$month" />
    <xsl:value-of select="'/'" />
    <xsl:value-of select="$day" />
    <xsl:value-of select="'/'" />
    <xsl:value-of select="$year" />
  </xsl:template>

</xsl:stylesheet>
